home *** CD-ROM | disk | FTP | other *** search
/ Programming Windows 95 with MFC / Programming Windows 95 with MFC (Microsoft Programming Series)(097-0001465)(1996).iso / NT / CODE / CHAP14 / MTDEMO / MAINFRAME.CPP next >
C/C++ Source or Header  |  1996-04-05  |  3KB  |  106 lines

  1. //***********************************************************************
  2. //
  3. //  MainFrame.cpp
  4. //
  5. //***********************************************************************
  6.  
  7. #include <afxwin.h>
  8. #include <afxext.h>
  9. #include <afxmt.h>
  10. #include "Resource.h"
  11. #include "MainFrame.h"
  12. #include "MTDoc.h"
  13.  
  14. IMPLEMENT_DYNCREATE (CMainFrame, CFrameWnd)
  15.  
  16. BEGIN_MESSAGE_MAP (CMainFrame, CFrameWnd)
  17.     ON_WM_CREATE ()
  18.     ON_MESSAGE (WM_USER_UPDATE_STATS, OnUpdateImageStats)
  19.     ON_MESSAGE (WM_USER_THREAD_UPDATE, OnThreadUpdate)
  20.     ON_MESSAGE (WM_USER_THREAD_FINISHED, OnThreadFinished)
  21.     ON_MESSAGE (WM_USER_THREAD_ABORTED, OnThreadAborted)
  22.     ON_WM_QUERYNEWPALETTE ()
  23.     ON_WM_PALETTECHANGED ()
  24. END_MESSAGE_MAP ()
  25.  
  26. CMainFrame::CMainFrame ()
  27. {
  28.     m_nPercentDone = -1;
  29. }
  30.  
  31. int CMainFrame::OnCreate (LPCREATESTRUCT lpcs)
  32. {
  33.     static UINT nIndicators[] = {
  34.         ID_SEPARATOR,
  35.         ID_SEPARATOR,
  36.     };
  37.  
  38.     if (CFrameWnd::OnCreate (lpcs) == -1)
  39.         return -1;
  40.  
  41.     if (!m_wndStatusBar.Create (this))
  42.         return -1;
  43.  
  44.     m_wndStatusBar.SetIndicators (nIndicators, 3);
  45.  
  46.     TEXTMETRIC tm;
  47.     CClientDC dc (this);
  48.     CFont* pFont = m_wndStatusBar.GetFont ();
  49.     CFont* pOldFont = dc.SelectObject (pFont);
  50.     dc.GetTextMetrics (&tm);
  51.     dc.SelectObject (pOldFont);
  52.  
  53.     int cxWidth;
  54.     UINT nID, nStyle;
  55.     m_wndStatusBar.GetPaneInfo (1, nID, nStyle, cxWidth);
  56.     m_wndStatusBar.SetPaneInfo (1, nID, nStyle, tm.tmAveCharWidth * 24);
  57.     m_wndStatusBar.SetPaneInfo (2, nID, nStyle, tm.tmAveCharWidth * 8);
  58.     return 0;
  59. }
  60.  
  61. LONG CMainFrame::OnUpdateImageStats (UINT wParam, LONG lParam)
  62. {
  63.     m_wndStatusBar.SetPaneText (1, (LPCTSTR) lParam, TRUE);
  64.     return 0;
  65. }
  66.  
  67. LONG CMainFrame::OnThreadUpdate (UINT wParam, LONG lParam)
  68. {
  69.     int nPercentDone = ((int) wParam * 100) / (int) lParam;
  70.     if (nPercentDone != m_nPercentDone) {
  71.         m_nPercentDone = nPercentDone;
  72.         CString string;
  73.         string.Format ("%d%%", m_nPercentDone);
  74.         m_wndStatusBar.SetPaneText (2, (LPCTSTR) string, TRUE);
  75.     }
  76.     return 0;
  77. }
  78.  
  79. LONG CMainFrame::OnThreadFinished (UINT wParam, LONG lParam)
  80. {
  81.     ((CMTDoc*) GetActiveDocument ())->ThreadFinished ();
  82.     m_wndStatusBar.SetPaneText (2, "", TRUE);
  83.     m_nPercentDone = -1;
  84.     return 0;
  85. }
  86.  
  87. LONG CMainFrame::OnThreadAborted (UINT wParam, LONG lParam)
  88. {                             
  89.     ((CMTDoc*) GetActiveDocument ())->ThreadAborted ();
  90.     m_wndStatusBar.SetPaneText (2, "", TRUE);
  91.     m_nPercentDone = -1;
  92.     return 0;
  93. }
  94.  
  95. BOOL CMainFrame::OnQueryNewPalette ()
  96. {
  97.     GetActiveView ()->Invalidate (FALSE);
  98.     return TRUE;
  99. }
  100.  
  101. void CMainFrame::OnPaletteChanged (CWnd* pFocusWnd)
  102. {
  103.     if (pFocusWnd != this)
  104.         GetActiveView ()->Invalidate (FALSE);
  105. }
  106.